#! /usr/bin/env python

import sys
import os
import shutil
import commands

def execute(cmd):
    o = commands.getstatusoutput(cmd)
    if o[0] != 0:
        print "Failed to execute cmd [%s], errno = [%d]" % (cmd, o[0])
        sys.exit(o[0])

    return o

def env_gen_main():
	if len(sys.argv) < 2:
		print "Error: Install Path has not been specified!"
		sys.exit(-1)

    install_root = sys.argv[1]

	bin_path = install_root + '/bin'
	conf_path = install_root + '/conf'
	log_path = install_root + '/log'

	execute('mkdir -p ' + bin_path)
	print('Create [' + bin_path + '] OK!')

	execute('mkdir -p ' + conf_path)
	print('Create [' + conf_path + '] OK!')

	execute('mkdir -p ' + log_path)
	print('Create [' + log_path + '] OK!')

    print 'Environment Generate Ok!'
    sys.exit(0)


if __name__ == '__main__':
    env_gen_main()
